package components

import (
	"fyne.io/fyne/v2"
)

type TightVBox struct{}

func (t *TightVBox) Layout(objects []fyne.CanvasObject, size fyne.Size) {
	y := float32(0)
	for _, child := range objects {
		child.Move(fyne.NewPos(0, y))
		child.Resize(fyne.NewSize(size.Width, child.MinSize().Height))
		y += child.MinSize().Height + 2 // 2像素间距
	}
}

func (t *TightVBox) MinSize(objects []fyne.CanvasObject) fyne.Size {
	width := float32(0)
	height := float32(0)
	for _, child := range objects {
		childSize := child.MinSize()
		if childSize.Width > width {
			width = childSize.Width
		}
		height += childSize.Height + 2 // 2像素间距
	}
	return fyne.NewSize(width, height)
}
